package com.ecloud.gardensterminal.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ecloud.gardensterminal.constant.DeviceTypeConstant;
import com.ecloud.gardensterminal.dao.GardensDeviceMapper;
import com.ecloud.gardensterminal.dao.GardensSwitchMapper;
import com.ecloud.gardensterminal.domain.GardensDevice;
import com.ecloud.gardensterminal.domain.GardensSwitch;
import com.ecloud.gardensterminal.server.GardensSwitchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Squbi
 */
@Service
public class GardensSwitchServiceImpl extends ServiceImpl<GardensSwitchMapper, GardensSwitch> implements GardensSwitchService {
    @Autowired
    private GardensSwitchMapper switchMapper;

    @Autowired
    private GardensDeviceMapper deviceMapper;

    @Override
    public List<GardensSwitch> selectNewly() {
        List<GardensDevice> gardensDevices = deviceMapper.selectByDeviceType(DeviceTypeConstant.SWITCH);
        ArrayList<GardensSwitch> result = new ArrayList<>();
        for (GardensDevice gardensDevice : gardensDevices) {
            GardensSwitch gardensSwitch = switchMapper.selectNewly(gardensDevice.getDeviceId());
            if (gardensSwitch != null) {
                result.add(gardensSwitch);
            }
        }
        return result;
    }
}
